<!--script>
$(document).ready(function(){
	var max_fields	= 10; //maximum input box allowed
	var wrapper		= $(".input_fields_wrap"); //field wrapper
	var add_button	= $(".add_field_button"); //add button ID
	
	var x =1; //initial text box count
	$(add_button).click(function(e){ // on add button click
		e.preventDefault();
		if(x < max_fields){ //max input box allowed
			x++; // text box increment
			$(wrapper).append('<div class="fitem"><input type="text" name="mytext[]" /><a href="#" class="remove_field">Hapus</a></div>'); // add input box
		}
	});
	
	$(wrapper).on("click",".remove_field", function(e){ // user click hapus field
		e.preventDefault();
		$(this).parent('div').remove(); x--;
	})
}
);
</script-->
<script>
$(document).ready(function(){
	$("#no_ktp").keyup(function(e){
		var val = $("#no_ktp").val();
		//alert(val);
		$.ajax({
			url : "<?=base_url();?>daftar_surat/penduduk_by_ktp/"+val,
			type: "GET",
			dataType: "json",
			success: function(data){
				$("#nama").val(data.nama);
				$("#j_kel").val(data.j_kel);
				$("#t_lahir").val(data.t_lahir);
				$("#tgl_lahir").val(data.tgl_lahir);
				$("#agama").val(data.agama);
				$("#pendidikan").val(data.pendidikan);
				$("#pekerjaan").val(data.pekerjaan);
				$("#s_nikah").val(data.s_nikah);
				console.log(data);
			}
		});
	});

	// save
	saveData = function(){
		$('#form1').form('submit',{
			url: url,
			onSubmit: function(){ //unttuk confirmasi surat
				//$.messager.alert('Print','Print Surat');
				//$.messager.confirm('Cetak Surat','PDF NANTI DI SINI ',
			},
			success: function(result){
				console.log(result);
				// return 1;
				var result = eval('('+result+')');
				if (result.success){
					$('#dialog').dialog('close');		// close the dialog
					//print pdf
					// result.no_surat
					print_sk(result.no_surat);
				} else {
					$.messager.show({
						title: 'Error',
						msg: result.msg
					});
				}
			}
		});
	}

	// print
	print_sk = function(id){ // id calon siswa
		//alert('tada....');
		popupwindow('<?=base_url()?>daftar_surat/pdf_sk/'+id, 'Print Surat Keterangan', 800, 500);
	}
});
</script>
<form id="form1" method="post" style="margin:10px;">
	<input name="nomer_surat" id="nomer_surat" value="<?=$nomer_surat?>" type="hidden">
	<div class="fitem" >
		<label style="width:120px">No. Surat</label>:
		<label style="width:150px"><?php echo $nomer_surat;?></label>
	</div>
	<div class="fitem">
		<label style="width:120px">No. KTP</label>:
		<input id="no_ktp" name="no_ktp" size="20" required="true" value="<?=set_value('no_ktp')?>">
	</div>
	<div class="fitem">
		<label style="width:120px">Nama Penduduk</label>:
		<input id="nama" name="nama" size="10" required="true" value="<?=set_value('nama')?>">
	</div>
	<div class="fitem">
		<label style="width:120px">Tempat Lahir</label>:
		<input id="t_lahir" name="t_lahir" size="20" required="true" value="<?=set_value('t_lahir')?>">
	</div>
	<div class="fitem">
		<label style="width:120px">Tanggal Lahir</label>:
		<input id="tgl_lahir" name="tgl_lahir" size="20" required="true" value="<?=set_value('tgl_lahir')?>">
	</div>
	<div class="fitem">
		<label style="width:120px">Jenis Kelamin</label>:
		<input id="j_kel" name="j_kel" size="20" required="true" value="<?=set_value('j_kel')?>">
	</div>
	<div class="fitem">
		<label style="width:120px">Agama</label>:
		<input id="agama" name="agama" size="20" required="true" value="<?=set_value('agama')?>">
	</div>
	<div class="fitem">
		<label style="width:120px">Pendidikan</label>:
		<input id="pendidikan" name="pendidikan" size="20" required="true" value="<?=set_value('pendidikan')?>">
	</div>
	<div class="fitem">
		<label style="width:120px">Pekerjaan</label>:
		<input id="pekerjaan" name="pekerjaan" size="20" required="true" value="<?=set_value('pekerjaan')?>">
	</div>
	<div class="fitem">
		<label style="width:120px">Status Pernikahan</label>:
		<input id="s_nikah" name="s_nikah" size="20" required="true" value="<?=set_value('s_nikah')?>">
	</div>
	<div class="fitem">
		<label style="width:120px">Alamat</label>:
		<input id="alamat" name"alamat" size="20" required="true" value="<?=$alamat?>">
	</div>
	<div class="fitem">
		<label style="width:120px;vertical-align:top;">Keterangan </label>
		<textarea name="keterangan" cols="35" rows="7"><?=$keterangan?></textarea>
	</div>
	<div class="fitem" >
		<label style="width:120px">Yang Tanda Tangan</label>:
		<select id="tanda_tangan" name="tanda_tangan">
			<option value="">- Pilih -</option>
			<option value="Kades" <?= $tanda_tangan == 'Kades'?'selected ="selected"':''; ?>>Kades</option>
			<option value="Sekdes" <?= $tanda_tangan == 'Sekdes'?'selected ="selected"':''; ?>>Sekdes</option>
		</select></li>
	</div>
</form>
	

